<% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":" +
    request.getServerPort() + path + "/" ; %>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
        <!DOCTYPE html>
        <html>

        <head>
            <base href="<%=basePath%>">
            <title>询价结果</title>
        </head>
        <style>
            .tdText {
                text-align: right;
                width: 400px;
                height: 20px;
            }

            input:disabled {
                background-color: #dae1ed;
            }
        </style>

        <body>
            <%@ include file="/WEB-INF/jsp/common/header.jsp" %>
                <%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

                    <script type="text/javascript">
                        $(function () {
                            /**
                             * 初始化日期选择框
                             */
                            $('#startTime').datebox('setValue', getBeforeCurrentDate90Days());
                            $('#endTime').datebox('setValue', getNowFormatDate());
                            $('#startInquiryTime').datebox('setValue', getBeforeCurrentDate90Days());
                            $('#endInquiryTime').datebox('setValue', getNowFormatDate());
                            bindMMCombo();
                            bindTransferCombo();
                            // 初始化列表
                            bingGrid();
                            // 初始化询价书查询列表
                            setInquiriesDataGrid()

                            $("#uploadbtn").bind("click", function (e) {
                                $("#uploadpicker").click();
                            });
                            if (PUser.superadmin != '1') {
                                $('#btnBack').hide();
                                $('#btnSubmit').hide();
                                $('#btnTransfer').hide();
                            }
                        });

                        function bindTransferCombo(userid) {
                            $('#transferName').combogrid({
                                panelWidth: 500,
                                url: 'sys/user/selectList?sap=sap',
                                queryParams: {
                                    q: userid
                                },
                                //                                 method: 'post',
                                idField: 'userid',
                                textField: 'username',
                                mode: 'remote',
                                fitColumns: true,
                                //                                 delay: 10000,
                                pagination: true,
                                columns: [[
                                    { field: 'userid', title: '用户id', hidden: true, width: 60 },
                                    { field: 'loginname', title: 'HI账号', width: 100 },
                                    { field: 'username', title: '用户姓名', width: 100 }
                                ]],
                                onLoadSuccess: function (data) {
                                    console.log('combo:', data);
                                    if (data.rows.length == 0) {
                                        $('#ordContractName').combogrid('setValue', '');
                                    } else {
                                        // $('#ordContractName').combogrid('setValue', data.rows[0].userid);
                                    }
                                }
                            });
                        }

                        function bindMMCombo(userid) {
                            $('#ordContractName').combogrid({
                                panelWidth: 500,
                                url: 'sys/user/selectList?sap=sap',
                                queryParams: {
                                    q: userid
                                },
                                //                                 method: 'post',
                                idField: 'userid',
                                textField: 'username',
                                mode: 'remote',
                                fitColumns: true,
                                //                                 delay: 10000,
                                pagination: true,
                                columns: [[
                                    { field: 'userid', title: '用户id', hidden: true, width: 60 },
                                    { field: 'loginname', title: 'HI账号', width: 100 },
                                    { field: 'username', title: '用户姓名', width: 100 }
                                ]],
                                onLoadSuccess: function (data) {
                                    console.log('combo:', data);
                                    if (data.rows.length == 0) {
                                        $('#ordContractName').combogrid('setValue', '');
                                    } else {
                                        //                                         $('#ordContractName').combogrid('setValue', data.rows[0].userid);
                                    }
                                }
                            });
                        }

                        //打开转交窗口
                        function openTransferDialog() {
                            $('#dlgTransfer').dialog('open');
                        }

                        //转交他人
                        function transfer() {
                            let order = $('#initTable').datagrid('getSelected')
                            if (!order) {
                                $.messager.alert('提示', '请选择一条数据')
                                return
                            } $.messager.confirm('提示', '确定要转交这个订单吗?', function (r) {
                                if (r) {
                                    var json = {
                                        resId: order.resId,
                                        inqActualId: $('#transferName').combogrid('getValue'),
                                        inqActualName: $('#transferName').combogrid('getText')
                                    }
                                    $.ajax({
                                        type: 'post',
                                        url: 'purchase/result/transfer?',
                                        data: JSON.stringify(json),
                                        contentType: "application/json",
                                        dataType: 'json',
                                        success: function (data) {
                                            if (data.code == 60200) {
                                                $.messager.alert('消息', data.msg)
                                                let dg = $('#initTable');
                                                dg.datagrid('enableFilter');
                                                dg.datagrid('load');
                                                $('#dlgTransfer').dialog('close');
                                            } else {
                                                $.messager.alert('消息', data.msg)
                                            }
                                        },
                                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                                            $.messager.alert('消息', errorThrown);
                                        }
                                    })

                                }
                            });
                        }
                    </script>

                    <div class="query_criteria" id="query_criteria">
                        <div style="margin: 5px 0px">
                            <label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox" name="startTime"
                                id="startTime"
                                data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
                                class="easyui-datebox" name="endTime" id="endTime"
                                data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                style="width: 150px" /> <label style="margin-left: 20px; font-size: 12px;">状态：</label>
                            <input class="easyui-combobox" id="status" name="status" style="width: 80px;" data-options="valueField: 'value',editable:false,
		textField: 'label',panelHeight:'auto',data: [{
			label: '全部',
			value: ''
		},{
			label: '待提交',
			value: '0',
			'selected':true
		},{
			label: '已提交',
			value: '1'
		},{
			label: '已完成',
			value: '2'
		}]">
                            <a id="search" href="javascript:void(0)" class="easyui-linkbutton"
                                data-options="iconCls:'icon-search'" onclick="searchInquiryResultList()">查询</a>
                            <a id="export" href="javascript:void(0)" class="easyui-linkbutton"
                                data-options="iconCls:'icon-export'" onclick="exportInquiryList()">导出</a>
                            <a id="btnBack" href="javascript:void(0)" class="easyui-linkbutton"
                                data-options="iconCls:'icon-search'" onclick="adminBackClick()">撤回</a>
                            <a id="btnSubmit" href="javascript:void(0)" class="easyui-linkbutton"
                                data-options="iconCls:'icon-search'" onclick="adminSubmitClick()">提交</a>
                            <a id="btnTransfer" href="javascript:void(0)" class="easyui-linkbutton"
                                data-options="iconCls:'icon-search'" onclick="openTransferDialog()">转交</a>
                        </div>
                        <div id="dlgTransfer" class="easyui-dialog" title="转交" data-options="closed:true,modal:true,iconCls:'icon-save',
                            buttons: [{
                                text:'转交',
                                iconCls:'icon-ok',
                                handler:function(){
                                    transfer();
                                }
                            }]" style="width:400px;height:200px;padding:10px">
                            <input id="transferName" class="easyui-combogrid" data-options="required:true"
                                style="width: 60%">
                        </div>
                        <table id="initTable"></table>
                        <!-- 询价结果编辑、详情弹窗 -->
                        <div id="resultDetaillWindow" class="easyui-window" closed="true" modal="true" title="询价结果"
                            style="width: 930px; height: 400px; padding: 5px 5px; top: 50px;">
                            <div id="tabs" class="easyui-tabs" data-options="selected:0"
                                style="width: 885px; height: 350px">
                                <div title="基本信息" style="padding: 5px;">
                                    <form id="resultForm">
                                        <table>
                                            <tr style="margin-bottom: 10px">
                                                <input type="hidden" name="resId" id="resId">
                                                <input type="hidden" name="inqId" id="inqId">
                                                <input type="hidden" name="gramId" id="gramId">
                                                <input type="hidden" name="oaFlowId" id="oaFlowId">
                                                <input type="hidden" name="oaSubmit" id="oaSubmit">
                                                <td colspan="1" class="tdText">
                                                    <div id="searchDiv" onclick="searchInquiries()">
                                                        <label style="width: 40%; text-align: right;">询价名称：</label>
                                                        <input data-options="prompt:'点击查询询价书'" id="inqName"
                                                            class="easyui-textbox" style="width: 60%">
                                                    </div>
                                                </td>
                                                <td colspan="1" class="tdText"><label
                                                        style="width: 40%; text-align: right;">询价编码：</label> <input
                                                        id="inqCode" class="easyui-validatebox textbox"
                                                        data-options="disabled:true" style="width: 60%"></td>
                                                <td colspan="1" class="tdText"><label
                                                        style="width: 40%; text-align: right;">结果编码：</label> <input
                                                        id="resCode" class="easyui-validatebox textbox"
                                                        data-options="disabled:true" style="width: 60%"></td>
                                                <%-- <td colspan="1" class="tdText">
                                                    <label style="width:40%;text-align:right;">结果名称：</label>
                                                    <input id="resName" class="easyui-validatebox textbox"
                                                        style="width: 60%">
                                                    </td>--%>
                                            </tr>
                                            <tr style="margin-bottom: 10px">
                                                <td colspan="1" class="tdText"><label style="width: 40%;">方案名称：</label>
                                                    <input id="gramName" class="easyui-textbox" style="width: 60%">
                                                </td>
                                                <td colspan="1" class="tdText"><label style="width: 40%;">币种：</label>
                                                    <input id="inqCurrency" style="width: 60%" class="easyui-combobox"
                                                        data-options="url:'sysDict/queryItemByTypeName?dicName=币种',method:'get',editable:false,required:true,
					                                                         valueField:'dicValue',textField:'dicName',panelHeight:'auto'">
                                                </td>
                                                <td colspan="1" class="tdText"><input type="hidden" id="ordContractId">
                                                    <label style="width: 40%; text-align: right;">合同执行人：</label>
                                                    <input id="ordContractName" class="easyui-combogrid"
                                                        data-options="required:true" style="width: 60%">
                                                    <!-- <input
                                                        id="ordContractName" class="easyui-textbox"
                                                        data-options="required:true" style="width: 60%"> -->
                                                </td>
                                                <%-- <td colspan="1" class="tdText"><label
                                                        style="width: 40%; text-align: right;">成交方式：</label> <input
                                                        id="inqDealMode" class="easyui-textbox" style="width: 60%">
                                                    </td> --%>
                                            </tr>
                                            <tr style="margin-bottom: 10px">
                                                <td colspan="1" class="tdText">
                                                    <label style="width: 40%; text-align: right;">是否外修：</label> <input
                                                        class="easyui-combobox" id="cobSFWX" name="cobSFWX"
                                                        style="width: 60%" data-options="required:true,valueField: 'value',editable:false,
                                            textField: 'label',panelHeight:'auto',data: [{
                                                label: '否',
                                                value: '0'
                                            },{
                                                label: '工程服务',
                                                value: '工程服务',
                                                selected:true
                                            },{
                                                label: '设备外修',
                                                value: '设备外修'
                                            }]">
                                                </td>
                                                <td colspan="1" class="tdText"><label
                                                        style="width: 40%; text-align: right;">报价方式：</label> <input
                                                        id="inqOfferMode" data-options="disabled:true"
                                                        class="easyui-textbox" style="width: 60%">
                                                </td>
                                                <td colspan="1" class="tdText"><label
                                                        style="width: 40%; text-align: right;">签订地点：</label> <input
                                                        id="resAddress" class="easyui-textbox" style="width: 60%">
                                                </td>
                                            </tr>
                                            <tr style="margin-bottom: 10px">

                                                <td colspan="1" class="tdText"><label
                                                        style="width: 50%;">报价开始时间：</label>
                                                    <input id="inqStartTime" class="easyui-datebox"
                                                        data-options="disabled:true" style="width: 50%">
                                                </td>
                                                <td colspan="1" class="tdText"><label
                                                        style="width: 50%; text-align: right;">报价结束时间：</label> <input
                                                        id="inqEndTime" data-options="disabled:true"
                                                        class="easyui-datebox" style="width: 50%"></td>

                                            </tr>
                                            <tr style="margin-bottom: 10px">
                                                <td colspan="1" class="tdText"><label
                                                        style="width: 50%; text-align: left;">报价揭示时间：</label> <input
                                                        id="inqRevealTime" class="easyui-datebox"
                                                        data-options="disabled:true" style="width: 50%"></td>
                                                <td colspan="1" class="tdText"><label
                                                        style="width: 50%; text-align: right;">实际揭示时间：</label> <input
                                                        id="inqActualTime" class="easyui-datebox"
                                                        data-options="disabled:true" style="width: 50%"></td>

                                                <%-- <td colspan="1" class="tdText"><label
                                                        style="width: 40%; text-align: right;">揭示人姓名：</label> <input
                                                        id="inqActualId" type="hidden"> <input id="inqActualName"
                                                        class="easyui-textbox" data-options="disabled:true"
                                                        style="width: 60%"></td>
                                                    <td colspan="1" class="tdText"><label
                                                            style="width: 40%; text-align: right;">价格条款：</label> <input
                                                            id="inqClause" class="easyui-textbox" style="width: 60%">
                                                    </td>--%>
                                            </tr>
                                            <tr style="margin-bottom: 10px">

                                                <td colspan="3" style="width: 800px;padding-left: 60px;"><label
                                                        style="width: 40%; text-align: right;">备注：</label> <input
                                                        id="remark" class="easyui-textbox"
                                                        style="width: 60%;height: 100px"
                                                        data-options="readonly:false,multiline:true">
                                                </td>

                                            </tr>
                                            <%-- <tr style="margin-bottom: 10px">
                                                <td colspan="1" class="tdText"><label
                                                        style="width: 40%; text-align: right;">创建时间：</label> <input
                                                        id="createName" class="easyui-datebox"
                                                        data-options="disabled:true" style="width: 60%">
                                                </td>
                                                <td colspan="1" class="tdText"><label
                                                        style="width: 40%; text-align: right;">修改人：</label> <input
                                                        id="updateName" class="easyui-textbox"
                                                        data-options="disabled:true" style="width: 60%">
                                                </td>
                                                <td colspan="1" class="tdText"><label
                                                        style="width: 40%; text-align: right;">修改时间：</label> <input
                                                        id="updateTime" class="easyui-datebox"
                                                        data-options="disabled:true" style="width: 60%">
                                                </td>
                                                </tr>--%>
                                        </table>
                                    </form>
                                </div>
                                <div title="供应商明细" style="padding: 5px;">
                                    <table id="suppliers"></table>
                                </div>
                                <div title="附件" style="padding: 5px;">
                                    <table>
                                        <tr>
                                            <td colspan="3"><input type="button" id="uploadbtn" value="选择文件..." />
                                                <input type="file" id="uploadpicker" accept="" onchange="changeFile()"
                                                    multiple style="display: none;" />
                                                <span>（文件名称不能包含斜杠、空格、&、#等特殊字符）</span>
                                            </td>

                                        </tr>
                                        <tr>
                                            <td><label style="width: 40%; text-align: right;">附件下载：</label>
                                                <ul id="checkfileList"></ul>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <!-- 选择已提交的询价书的弹窗 -->
                        <div id="selectInquiryWindow" class="easyui-window" closed="true" modal="true" title="询价书列表"
                            style="width: 900px; height: 400px; padding: 5px;">
                            <!-- 搜索框 -->
                            <label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox"
                                id="startInquiryTime"
                                data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
                                class="easyui-datebox" id="endInquiryTime"
                                data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                style="width: 150px" />
                            <!-- <label style="margin-left: 20px; font-size: 12px;">状态：</label>
                            <input class="easyui-combobox" id="statusInq" name="statusInq" style="width: 80px;"
                                data-options="valueField: 'value',editable:false,
            textField: 'label',panelHeight:'auto',data: [{
                label: '已提交',
                value: '1',
                'selected':true
            },{
                label: '已完成',
                value: '2'
            }]" /> -->
                            <a style="margin-left: 30px" href="javascript:void(0)" class="easyui-linkbutton"
                                data-options="iconCls:'icon-search'" onclick="selectInquiryList()">查询</a> <a
                                style="margin-left: 5px" href="javascript:void(0)" class="easyui-linkbutton"
                                data-options="iconCls:'icon-ok'" onclick="getSelectedInquiry()">确定</a>
                            <!--询价书列表DataGrid  -->
                            <table id="inquiryList"></table>
                        </div>
                        <!-- 物资报价列表弹窗 -->
                        <div id="mmOffersWindow" class="easyui-window" closed="true" modal="true" title="报价明细表"
                            style="width: 900px; height: 400px; padding: 5px 5px; top: 50px;">
                            <table id="mmOffers"></table>
                        </div>
                    </div>
        </body>
        <script>
            var selectedFileList = [];//已选文件列表
            var succsessCount = 0;//上传成功文件个数
            var errorCount = 0;//上传失败文件个数
            var editIndex = undefined;
            var editIndexMm = undefined;
            var purchaseSupplyOfferMms = [];

            // 供应商明细行编辑结束
            function endEditing() {
                console.log('editIndex...', editIndex)
                if (editIndex == undefined) {
                    return true
                }
                let ed = $('#suppliers').datagrid('getEditor', { index: editIndex, field: 'dealIsCheck' })
                let flag = $(ed.target).combobox('getValue')
                console.log('row.dealIsCheck,,,,', flag)

                if (flag == "0") {
                    $('#suppliers').datagrid('endEdit', editIndex);
                    editIndex = undefined;
                    return true;
                } else {
                    if ($('#suppliers').datagrid('validateRow', editIndex)) {
                        $('#suppliers').datagrid('endEdit', editIndex);
                        editIndex = undefined;
                        return true;
                    } else {
                        alert('请先完成本行必填数据录入!');
                        return false;
                    }
                }

            }

            // 行编辑结束
            function endEditingMMs() {
                if (editIndexMm == undefined) {
                    return true
                }
                console.log('editIndexMm===', editIndexMm)
                if ($('#mmOffers').datagrid('validateRow', editIndexMm)) {
                    $('#mmOffers').datagrid('endEdit', editIndexMm);
                    editIndexMm = undefined;
                    return true;
                } else {
                    alert('请先完成本行必填数据录入!');
                    return false;
                }
            }

            var dealIsCheckOptions = [{
                "dealIsCheck": "0",
                "text": "否"
            }, {
                "dealIsCheck": "1",
                "text": "是"
            }];
            var inqIsSettleOptions = [{
                "inqIsSettle": "1",
                "text": "按原发数结算"
            }, {
                "inqIsSettle": "2",
                "text": "按实收数结算"
            }];
            var inqIsWeightOptions = [{
                "inqIsWeight": "1",
                "text": "无需过磅"
            }, {
                "inqIsWeight": "2",
                "text": "需过磅"
            }];
            var inqIsOwnOptions = [{
                "inqIsOwn": "1",
                "text": "自提"
            }, {
                "inqIsOwn": "2",
                "text": "供应商送货"
            }];

            var inqIsFreeOptions = [{
                "inqIsFree": "1",
                "text": "付费"
            }, {
                "inqIsFree": "X",
                "text": "免费"
            }];

            var inqBackGoodOptions = [{
                "inqBackGood": "1",
                "text": "采购"
            }, {
                "inqBackGood": "X",
                "text": "退货"
            }];

            $('#resultDetaillWindow').window({
                onBeforeClose: function () {
                    endEditing();
                }
            })
            /**
             * 新增询价结果
             */
            function addInquirResult() {
                // 1.清空form
                $('#resultForm').form('clear')
                selectedFileList = []
                $("#checkfileList").empty();
                // 清空datagrid
                setMmsOfferDatagrid([])
                setSuppliersDatagrid([])
                // $('#inqName').textbox({disabled: false})
                $('#inqCode').textbox({ disabled: false })
                $('#cobSFWX').combobox('setValue', '0')
                $('#selectInquiryWindow').window({
                    onBeforeOpen: function () {
                        return true
                    }
                })
                $('#tabs').tabs({
                    tools: [{
                        text: '保存',
                        iconCls: 'icon-save',
                        handler: function () {
                            saveInquiryResult('save', '0');
                        }
                    }, {
                        text: '提交',
                        iconCls: 'icon-ok',
                        handler: function () {
                            $.messager.confirm('提示', '提交后会推送OA审核，无法再次编辑，确定要提交吗?（注意：oa退回后不要删除及转发流程，需先在cmp撤回）',
                                function (r) {
                                    if (r) {
                                        saveInquiryResult('submit', '1')
                                    }
                                });
                        }
                    }]
                })
                $('#resultDetaillWindow').window('open')
                $('#tabs').tabs('select', 0)
            }

            function setTabToolBar(status) {
                if ('1' == status) {
                    $('#tabs').tabs({
                        tools: [{
                            text: '保存',
                            iconCls: 'icon-save',
                            handler: function () {
                                saveInquiryResult('save', '0');
                            }
                        }, {
                            text: '提交',
                            iconCls: 'icon-ok',
                            handler: function () {
                                $.messager.confirm('提示', '提交后会推送OA审核，无法再次编辑，确定要提交吗?',
                                    function (r) {
                                        if (r) {
                                            saveInquiryResult('submit', '1')
                                        }
                                    });
                            }
                        }]
                    })
                } else {
                    $('#tabs').tabs({
                        tools: ''
                    })
                }
            }

            /**
             * 加载询价书弹窗
             */
            function searchInquiries() {
                selectInquiryList();
                $('#selectInquiryWindow').window('open');
            }

            // 询价书选择的datagrid
            function setInquiriesDataGrid() {
                // 构建查询询价书的dataGrid
                let startTime = $('#startInquiryTime').datebox('getValue')
                let endTime = $('#endInquiryTime').datebox('getValue')
                // let status = $('#statusInq').datebox('getValue')
                let inquiryDataGrid = $('#inquiryList')
                inquiryDataGrid.datagrid({
                    queryParams: {
                        startTime: startTime ? startTime : '',
                        endTime: endTime ? endTime : '',
                        inqRevealStatus: '1'
                    },
                    fitColumns: true,
                    url: 'purchase/selectInquiryList',
                    iconCls: 'icon-application',
                    clientPaging: false,
                    remoteFilter: true,
                    filterDelay: 0,
                    width: 860,
                    height: 310,
                    nowrap: true,
                    rownumbers: true,
                    animate: false,
                    collapsible: false,
                    singleSelect: true,
                    pageSize: 10,
                    remoteSort: true,
                    pagination: true,
                    columns: [
                        [{
                            field: 'ck',
                            checkbox: true,
                            width: 100,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        }, {
                            field: 'inqId',
                            title: '询价书ID',
                            hidden: true,
                            sortable: true,
                            width: 100,
                            formatter: function (val, rec) {
                                return unescape(val)
                            }
                        },
                        {
                            field: 'inqName',
                            title: '询价名称',
                            sortable: true,
                            formatter: function (val, rec, index) {
                                return val ? val : ''
                            }
                        },
                        {
                            field: 'inqCode',
                            title: '询价编码',
                            sortable: true,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        }, {
                            field: 'gramName',
                            title: '采购方案名称',
                            sortable: true,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        {
                            field: 'inqStartTime',
                            title: '报价开始时间',
                            sortable: true,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        {
                            field: 'inqEndTime',
                            title: '报价结束时间',
                            sortable: true,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        {
                            field: 'inqRevealTime',
                            title: '报价揭示时间',
                            sortable: true,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        {
                            field: 'inqActualTime',
                            title: '实际揭示时间',
                            sortable: true,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        {
                            field: 'inqActualName',
                            title: '揭示人姓名',
                            sortable: true,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        {
                            field: 'createTime',
                            title: '创建时间',
                            sortable: true,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        },
                        {
                            field: 'updateTime',
                            title: '更新时间',
                            sortable: true,
                            formatter: function (val, rec) {
                                return unescape(val ? val : '')
                            }
                        }
                        ]
                    ],
                    toolbar: [
                        //     {
                        //     text: '确定',
                        //     iconCls: 'icon-ok',
                        //     handler: function () {
                        //         getSelectedInquiry()
                        //     }
                        // }
                    ],
                    onLoadSuccess: function () {
                    },
                })
                inquiryDataGrid.datagrid('enableFilter');
            }

            /**
             *获取已选择的询价书数据,赋值询价结果的新增弹窗
             */
            function getSelectedInquiry() {
                // 获取选择的询价书
                let row = $('#inquiryList').datagrid('getSelected')
                if (!row) {
                    $.messager.alert('提示', '请选择一条询价书数据')
                    return
                }
                // 赋值
                $('#inqName').textbox('setValue', row.inqName)
                $('#inqId').val(row.inqId)
                $('#gramId').val(row.gramId)
                $('#inqCode').textbox('setValue', row.inqCode)
                $('#gramName').textbox('setValue', row.gramName)
                $('#inqOfferMode').textbox('setValue', row.inqOfferMode)
                // $('#inqDealMode').textbox('setValue', row.inqDealMode)
                $('#inqStartTime').datebox('setValue', row.inqStartTime)
                $('#inqEndTime').datebox('setValue', row.inqEndTime)
                $('#inqRevealTime').datebox('setValue', row.inqRevealTime)
                $('#inqActualTime').datebox('setValue', row.inqActualTime)
                $('#inqClause').val(row.inqClause)
                $('#remark').textbox('setValue', row.remark)
                $('#resAddress').textbox('setValue', row.resAddress)
                /*  $('#inqActualId').val(row.inqActualId)
                  $('#inqActualName').textbox('setValue', row.inqActualName)
                  $('#createName').datebox('setValue', row.createName)
                  $('#updateName').textbox('setValue', row.updateName)
                  $('#updateTime').datebox('setValue', row.updateTime)*/

                let inqId = row.inqId
                $.ajax({
                    type: 'get',
                    url: 'purchase/selectInquiry?inqId=' + inqId,
                    dataType: 'json',
                    success: function (data) {
                        if (data.code != 60200) {
                            $.messager.alert('消息', '未查询到数据');
                        } else {
                            let inq = data.data
                            if (!inq) return
                            // 物资明细
                            purchaseSupplyOfferMms = inq.purchaseSupplyOfferMms
                            for (let item of purchaseSupplyOfferMms) {
                                item.status = 0;
                                item.inqTransportTaxRate = '9'
                                if (item.rank != '1' && item.inqDealMode == '分项成交') {
                                    item.dealNum = 0;//只有排名第一默认有中标数量
                                    // item.dealLastUnit = 0;
                                    // item.dealUnitPrice = 0;
                                    // item.dealTotalPrice = 0;
                                }
                            }
                            // 供应商明细
                            const purchaseSupplyOffers = []
                            for (let item of inq.purchaseSupplyOffers) {
                                if (item.status == '1') {
                                } else {
                                    $.messager.alert('消息', item.infName + '未提交报价，仍处于保存状态');
                                }
                                if (item.rank == '1' && item.inqDealMode == '总价成交') {
                                    item.dealIsCheck = '1';
                                } else {
                                    item.dealIsCheck = '0';
                                }
                                purchaseSupplyOffers.push(Object.assign({}, item, {
                                    infFirstTotalPrice: item.inqOfrTotalPrice,
                                    infFirstNum: item.inqOfrNum
                                }))
                            }
                            // 构建供应商明细
                            setSuppliersDatagrid(purchaseSupplyOffers)
                        }
                    }
                })
                $('#selectInquiryWindow').window('close')
            }

            /**
             * 查看供应商物资报价明细
             */
            function checkOfferOfSuppliers() {
                endEditingMMs();
                endEditing();
                let supplyRow = $('#suppliers').datagrid('getSelected')
                if (!supplyRow) {
                    $.messager.alert('提示', '请选择一条数据')
                }
                if (!purchaseSupplyOfferMms || purchaseSupplyOfferMms.length < 1) {
                    $.messager.alert('提示', '无报价信息')
                    return
                }
                console.log('purchaseSupplyOfferMms:', purchaseSupplyOfferMms);
                // return
                // 取得供应商id
                let infId = supplyRow.infId
                // 获取供应商物资报价数组
                const supplyOfferMMsArr = []
                for (let index = 0; index < purchaseSupplyOfferMms.length; index++) {
                    if (purchaseSupplyOfferMms[index].infId == infId) {
                        //  按索引删除元素并返回包含被删除元素的新数组
                        const item = purchaseSupplyOfferMms.splice(index, 1)
                        console.log('item:', item[0])
                        index--
                        if (item.length > 0) {
                            supplyOfferMMsArr.push(item[0])
                        }
                    }
                }
                if (!supplyOfferMMsArr || supplyOfferMMsArr.length < 1) {
                    $.messager.alert('提示', '该供应商无报价信息，先点击维护报价按钮')
                    return
                }
                setMmsOfferDatagrid(supplyOfferMMsArr)
                console.log('supplyOfferMMsArr:', supplyOfferMMsArr);
                $('#mmOffersWindow').window('open')
            }

            /**
             * 物资报价明细窗口关闭后的事件
             */
            $('#mmOffersWindow').window({
                onBeforeClose: function () {
                    if (endEditingMMs()) {
                        return true
                    } else {
                        return false
                    }
                },
                onClose: function () {
                    putDataToTempArr()
                }
            })

            /**
             * 报价明细编辑完成后的方法
             */
            function putDataToTempArr() {
                // 将报价明细放入临时数组
                const rows = $('#mmOffers').datagrid('getRows')
                console.log('purchaseSupplyOfferMms0:', purchaseSupplyOfferMms);
                if (rows && rows.length > 0) {
                    //成交总数量
                    let totalDealNum = 0
                    // 成交单价
                    let totalDealUnitPrice = 0
                    // 成交总金额（中标总金额）
                    let dealTotalPriceT = 0
                    // 运费金额
                    let inqTransportTotalPrice = 0
                    for (let row of $('#mmOffers').datagrid('getRows')) {
                        /**
                         *  将每个供应商的成交数量、成交单价、成交总金额、运费汇总
                         */
                        let dealNum = row.dealNum ? Number(row.dealNum) : 0
                        totalDealNum += dealNum
                        if (row.status == 0) {
                            row.dealUnitPrice = row.dealLastUnit;
                        }
                        let dealUnitPrice = row.dealUnitPrice ? Number(row.dealUnitPrice) : 0
                        totalDealUnitPrice += dealUnitPrice

                        // 成交总金额
                        row.dealTotalPrice = (Number(dealNum) * Number(dealUnitPrice)).toFixed(2);
                        console.log(' row.dealTotalPrice', row.dealTotalPrice);
                        dealTotalPriceT += row.dealTotalPrice

                        // 运费单价
                        let inqTransportUnitPrice = row.inqTransportTaxPrice ?
                            row.inqTransportTaxPrice / (1 + row.inqTransportTaxRate / 100) : 0;
                        inqTransportUnitPrice = inqTransportUnitPrice.toFixed(2);
                        row.inqTransportUnitPrice = inqTransportUnitPrice;
                        // 运费总价
                        row.inqTransportTotalPrice = Number(dealNum) * Number(inqTransportUnitPrice)
                        inqTransportTotalPrice += row.inqTransportTotalPrice
                        console.log('rows[i]:', row);
                        purchaseSupplyOfferMms.splice(purchaseSupplyOfferMms.length + 1, 0, row)
                    }
                    console.log('purchaseSupplyOfferMms1:', purchaseSupplyOfferMms);
                    // 更新供应商的中标金额、中标数量、中标单价、运费金额字段
                    /* let supplyRow = $('#suppliers').datagrid('getSelected')
                    let rowIndex = $('#suppliers').datagrid('getRowIndex', supplyRow)
                   $('#suppliers').datagrid('updateRow', {
                        index: rowIndex,
                        row: {
                            infLastTotalPrice: dealTotalPriceT,
                            infNum: totalDealNum,
                            infUnitPrice: totalDealUnitPrice,
                            infTransportCost: inqTransportTotalPrice
                        }
                    })*/
                }
            }

            /**
             * 保存/提交方法
             */
            function saveInquiryResult(action, oaSubmit) {
                if (!endEditing()) {
                    return;
                }
                endEditingMMs();
                if (!$('#resultForm').form('validate')) {
                    alert('请完成必填项输入');
                    return;
                }
                if (!$('#ordContractName').combogrid('getValue')) {
                    alert('合同执行人不存在');
                    return;
                }
                if (!checkComboGridValue('ordContractName', 'userid')) {
                    alert('请重新选择合同执行人');
                    return;
                }
                if ($('#gramName').val().includes('&') || $('#gramName').val().includes('\\') || $('#gramName').val().includes(' ')) {
                    alert('方案名称不能包括斜杠、空格、&等特殊字符');
                    return;
                }
                $('#suppliers').datagrid('acceptChanges');
                // 获取物资明细rows
                const purchaseSupplyDealMms = purchaseSupplyOfferMms
                console.log('purchaseSupplyOfferMms.....', purchaseSupplyOfferMms)
                for (let item of purchaseSupplyDealMms) {
                    if (!item.inqTaxNum) {
                        alert(item.mmCode + ':请选择税码!');
                        return;
                    }
                }
                // 获取供应商rows
                const purchaseSupplyDeals = $('#suppliers').datagrid('getRows')
                console.log('purchaseSupplyDeals.....', purchaseSupplyDeals)
                // 中标供应商
                let resUnit = ''
                // 中标总金额
                let resMoney = 0
                // 中标总数量
                let resNum = 0
                if (purchaseSupplyDeals != null && purchaseSupplyDeals.length > 0) {
                    for (let i in purchaseSupplyDeals) {
                        let infId = purchaseSupplyDeals[i].infId
                        let ck = purchaseSupplyDeals[i].dealIsCheck
                        let ckedSupply = purchaseSupplyDeals[i].infName ? purchaseSupplyDeals[i].infName : ''
                        // 中选
                        if ('1' == ck) {
                            // 中标供应商名称拼接
                            resUnit += ckedSupply + ','
                            // 单个供应商运费
                            let infTransportCostTemp = 0;
                            // 单个供应商最终报价
                            let infLastTotalPriceTemp = 0;
                            // 单个供应商中标总数量
                            let infNumTemp = 0;
                            // 汇总中标金额：将中选供应商的物资成交价格汇总赋值给询价结果列表
                            for (let j in purchaseSupplyDealMms) {
                                if (!purchaseSupplyDealMms[j].inqTaxNum) {
                                    alert('请维护税码等必填信息');
                                    return;
                                }
                                if (purchaseSupplyDealMms[j].inqIsFree == '1' && purchaseSupplyDealMms[j].dealUnitPrice <= 0) {
                                    // alert('中标物资为付费标记时,单价不能为0');
                                    // return;
                                }
                                // 匹配属于某个供应商的物资
                                if (purchaseSupplyDealMms[j].infId == infId) {
                                    if ('1' == ck) {
                                        // 汇总运费
                                        infTransportCostTemp += purchaseSupplyDealMms[j].inqTransportTotalPrice ? Number(purchaseSupplyDealMms[j].inqTransportTotalPrice) : 0
                                        // 将每条物资的成交价格与数量汇总成最终
                                        // infLastTotalPriceTemp += purchaseSupplyDealMms[j].dealTotalPrice ? Number(purchaseSupplyDealMms[j].dealTotalPrice) : 0
                                        infNumTemp += purchaseSupplyDealMms[j].dealNum ? Number(purchaseSupplyDealMms[j].dealNum) : 0
                                        infLastTotalPriceTemp += purchaseSupplyDealMms[j].dealNum * purchaseSupplyDealMms[j].dealUnitPrice
                                    }
                                }
                            }
                            purchaseSupplyDeals[i].infTransportCost = infTransportCostTemp.toFixed(2)
                            purchaseSupplyDeals[i].infLastTotalPrice = infLastTotalPriceTemp.toFixed(2)
                            purchaseSupplyDeals[i].infNum = infNumTemp
                            // 汇总中标金额
                            resMoney += infLastTotalPriceTemp ? infLastTotalPriceTemp : 0
                            // 汇总中标数量
                            resNum += infNumTemp ? Number(infNumTemp) : 0
                        } else {
                            // 单个供应商运费
                            let infTransportCostTemp = 0;
                            // 单个供应商最终报价
                            let infLastTotalPriceTemp = 0;
                            // 单个供应商中标总数量
                            let infNumTemp = 0;
                            // 汇总中标金额：将中选供应商的物资成交价格汇总赋值给询价结果列表
                            for (let j in purchaseSupplyDealMms) {
                                if (!purchaseSupplyDealMms[j].inqTaxNum) {
                                    alert('请维护税码等必填信息');
                                    // return;
                                }
                                // 匹配属于某个供应商的物资
                                if (purchaseSupplyDealMms[j].infId == infId) {
                                    // 汇总运费
                                    infTransportCostTemp += purchaseSupplyDealMms[j].inqTransportTotalPrice ? Number(purchaseSupplyDealMms[j].inqTransportTotalPrice) : 0
                                    // 将每条物资的成交价格与数量汇总成最终
                                    infLastTotalPriceTemp += purchaseSupplyDealMms[j].dealTotalPrice ? Number(purchaseSupplyDealMms[j].dealTotalPrice) : 0
                                    infNumTemp += purchaseSupplyDealMms[j].dealNum ? Number(purchaseSupplyDealMms[j].dealNum) : 0
                                }
                            }
                            purchaseSupplyDeals[i].infTransportCost = infTransportCostTemp.toFixed(2)
                            purchaseSupplyDeals[i].infLastTotalPrice = infLastTotalPriceTemp.toFixed(2)
                            purchaseSupplyDeals[i].infNum = infNumTemp
                        }
                    }
                }
                for (var row of purchaseSupplyDeals) {
                    if (isNaN(row.infLastTotalPrice) || !row.infLastTotalPrice) {
                        $.messager.alert('提示', '请先点击"维护报价"按钮！');
                        return;
                    }
                }
                // 去掉逗号
                if (resUnit.length > 0) {
                    resUnit = (resUnit.substring(resUnit.length - 1) == ',') ? resUnit.substring(0, resUnit.length - 1) : resUnit;
                }
                var row = $('#initTable').datagrid('getSelected');
                console.log('row:', row);
                const purchaseInquiryResultVO = {
                    status: action == 'save' ? '0' : '1',
                    // 中标单位
                    resUnit: resUnit,
                    // 中标金额/最终报价
                    resMoney: resMoney,
                    // 中标数量
                    resNum: resNum,
                    inqId: $('#inqId').val(),
                    gramId: $('#gramId').val(),
                    resId: $('#resId').val(),
                    inqName: $('#inqName').textbox('getValue'),
                    inqCode: $('#inqCode').val(),
                    oaFlowId: $('#oaFlowId').val(),
                    resCode: $('#resCode').val(),
                    gramName: $('#gramName').val(),
                    inqOfferMode: $('#inqOfferMode').val(),
                    inqDealMode: $('#inqDealMode').val(),
                    inqCurrency: $('#inqCurrency').combobox('getValue'),
                    inqCurrencyName: $('#inqCurrency').combobox('getText'),
                    inqStartTime: $('#inqStartTime').datebox('getValue'),
                    inqEndTime: $('#inqEndTime').datebox('getValue'),
                    inqRevealTime: $('#inqRevealTime').datebox('getValue',),
                    inqActualTime: $('#inqActualTime').datebox('getValue'),
                    inqClause: $('#inqClause').val(),
                    remark: $('#remark').textbox('getValue'),
                    inqOaStatus: $('#cobSFWX').combobox('getValue'),
                    resAddress: $('#resAddress').textbox('getValue'),
                    inqActualId: $('#ordContractName').combogrid('getValue'),
                    inqActualName: $('#ordContractName').combogrid('getText'),
                    oaSubmit: oaSubmit,
                    /*   createName: $('#createName').datebox('getValue'),
                       updateName: $('#updateName').val(),
                       updateTime: $('#updateTime').datebox('getValue'),*/
                    purchaseSupplyDeals: purchaseSupplyDeals,
                    purchaseSupplyDealMms: purchaseSupplyDealMms
                }

                save(purchaseInquiryResultVO, action)
            }

            function adminBackClick() {
                $.messager.confirm('提示', '确定要撤回吗?',
                    function (r) {
                        if (r) {
                            let row = $('#initTable').datagrid('getSelected')
                            backAdmin(row);
                        }
                    });
            }

            function backAdmin(resultObj) {
                if (resultObj) {
                    $.ajax({
                        type: 'post',
                        url: 'purchase/result/backAdmin',
                        data: JSON.stringify(resultObj),
                        dataType: 'json',
                        contentType: "application/json",
                        success: function (data) {
                            if (data.code == 60200) {
                                $.messager.alert('消息', data.msg)
                                let dg = $('#initTable');
                                dg.datagrid('enableFilter');
                                dg.datagrid('load');
                            } else {
                                $.messager.alert('消息', data.msg)
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            $.messager.alert('消息', errorThrown);
                        }
                    })
                } else {
                    alert('请选择一条数据！');
                }
            }
            /**
             * 保存的ajax
             */
            function save(obj, action) {
                $.ajax({
                    type: "post",
                    dataType: "json",
                    url: 'purchase/result/saveResult',
                    data: JSON.stringify(obj),
                    contentType: "application/json",
                    success: function (data) {
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        disLoad();
                        $.messager.alert('消息', errorThrown);
                    },
                    complete: function (XMLHttpRequest) {
                        console.log('XMLHttpRequest:', XMLHttpRequest)
                        if (XMLHttpRequest.responseJSON.code != 60200) {
                            $.messager.alert('消息', XMLHttpRequest.responseJSON.msg);
                        } else {
                            const result = XMLHttpRequest.responseJSON.data
                            // 保存附件
                            obj.resId = result.resId;
                            obj.oaSubmit = result.oaSubmit;
                            obj.oaFlowId = result.oaFlowId;
                            $('#oaFlowId').val(result.oaFlowId);
                            saveAttch(result.resId, result, action)
                            if ('save' == action) {
                            }

                        }
                    }
                })
            }

            /**
             * 提交的ajax
             */
            function commitResult(obj) {
                obj.status = '1'
                $.ajax({
                    type: "post",
                    dataType: "json",
                    url: 'purchase/result/commitResult',
                    data: JSON.stringify(obj),
                    contentType: "application/json",
                    success: function (data) {
                        $.messager.alert('消息', data.msg);
                        if (data.code != 60200) {
                        } else {
                            let dg = $('#initTable');
                            dg.datagrid('enableFilter');
                            dg.datagrid('load');
                            $('#resultDetaillWindow').window('close');
                            setInquiriesDataGrid();
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                })
            }
            /**
             * 提交的ajax
             */
            function adminSubmitClick() {
                $.messager.confirm('提示', '确定要重新提交吗?',
                    function (r) {
                        if (r) {
                            let row = $('#initTable').datagrid('getSelected')
                            if (row) {
                                $.ajax({
                                    type: "post",
                                    dataType: "json",
                                    url: 'purchase/result/commitAdmin',
                                    data: JSON.stringify(row),
                                    contentType: "application/json",
                                    success: function (data) {
                                        $.messager.alert('消息', data.msg);
                                        if (data.code != 60200) {
                                        } else {
                                            let dg = $('#initTable');
                                            dg.datagrid('enableFilter');
                                            dg.datagrid('load');
                                            $('#resultDetaillWindow').window('close');
                                            setInquiriesDataGrid();
                                        }
                                    },
                                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                                        $.messager.alert('消息', errorThrown);
                                    }
                                })
                            } else {
                                alert('请选择数据！');
                            }
                        }
                    })
            }

            /**
             * 查看询价结果详情
             */
            function inquiryResultDetail(index) {

                const rows = $('#initTable').datagrid('getRows')
                let row = rows[index]
                setTabToolBar(0)
                getResult(row.resId)
            }

            /**
             * 编辑
             */
            function updateInquiryResult() {
                let row = $('#initTable').datagrid('getSelected')
                if (!row) {
                    $.messager.alert('提示', '请选择一条数据')
                    return
                }
                if (+row.status != '0') {
                    $.messager.alert('提示', '该数据已提交，无法再次编辑')
                    return
                }


                $('#inqName').textbox({ disabled: true })
                $('#inqCode').textbox({ disabled: true })

                setTabToolBar(1)
                let resId = row.resId
                // 取得询价结果详情
                getResult(resId)

            }

            /**
             * 审核
             */
            function checkInquiryResult() {
                let row = $('#initTable').datagrid('getSelected')
                if (!row) {
                    $.messager.alert('提示', '请选择一条数据')
                    return
                }
                if (+row.status != '1') {
                    $.messager.alert('提示', '审批过程中才可操作')
                    return
                }

                $('#inqName').textbox({ disabled: true })
                $('#inqCode').textbox({ disabled: true })
                //采购员保存时不更改状态，依靠deptname区分是否发起oa流程
                $('#tabs').tabs({
                    tools: [{
                        text: '保存',
                        iconCls: 'icon-save',
                        handler: function () {
                            saveInquiryResult('submit', '0');
                        }
                    }, {
                        text: '提交',
                        iconCls: 'icon-ok',
                        handler: function () {
                            $.messager.confirm('提示', '提交后会推送OA审核，无法再次编辑，确定要提交吗?',
                                function (r) {
                                    if (r) {
                                        saveInquiryResult('submit', '1')
                                    }
                                });
                        }
                    }]
                })
                let resId = row.resId
                // 取得询价结果详情
                getResult(resId)
            }

            /**
             *根据resId查询结果详情
             */
            function getResult(resId) {
                // 编辑/详情时，不可再次打开询价书窗口
                $('#selectInquiryWindow').window({
                    onBeforeOpen: function () {
                        return false
                    }
                })
                $.ajax({
                    type: 'get',
                    dataType: 'json',
                    url: "purchase/result/selectResultInfo?resId=" + resId,
                    success: function (data) {
                        if (data.code != 60200) {
                            $.messager.alert('消息', '未查询到数据');
                        } else {
                            let result = data.data
                            if (!result) return
                            console.log('result...', result)
                            $('#resId').val(result.resId)
                            $('#inqName').textbox('setValue', result.inqName)
                            $('#inqId').val(result.inqId)
                            $('#gramId').val(result.gramId)
                            $('#inqCode').val(result.inqCode)
                            $('#resCode').val(result.resCode)
                            $('#oaFlowId').val(result.oaFlowId)
                            $('#gramName').textbox('setValue', result.gramName)
                            $('#inqOfferMode').val(result.inqOfferMode)
                            $('#inqDealMode').val(result.inqDealMode)
                            $('#inqCurrency').combobox('setValue', result.inqCurrency)
                            $('#inqStartTime').datebox('setValue', result.inqStartTime)
                            $('#inqEndTime').datebox('setValue', result.inqEndTime)
                            $('#inqRevealTime').datebox('setValue', result.inqRevealTime)
                            $('#inqActualTime').datebox('setValue', result.inqActualTime)
                            $('#inqClause').val(result.inqClause)
                            $('#remark').textbox('setValue', result.remark)
                            // $('#inqActualId').val(result.inqActualId)
                            bindMMCombo(result.inqActualId);
                            $('#ordContractName').combogrid('setValue', result.inqActualId);
                            $('#ordContractName').combogrid('setText', result.inqActualName)
                            $('#cobSFWX').combobox('setValue', result.inqOaStatus)
                            $('#resAddress').textbox('setValue', result.resAddress)
                            $('#createName').datebox('setValue', result.createName)
                            $('#updateName').val(result.updateName)
                            $('#updateTime').datebox('setValue', result.updateTime)
                            // 取得附件列表
                            getFileList(result)
                            purchaseSupplyOfferMms = result.purchaseSupplyDealMms
                            const purchaseSupplyDeals = result.purchaseSupplyDeals
                            setSuppliersDatagrid(purchaseSupplyDeals)
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                })
                $('#resultDetaillWindow').window('open');
                $('#tabs').tabs('select', 0)
            }
            function cellStyler(value, row, index) {
                return 'background-color:#ffee00;color:red;';
            }

            /**
             * 构建供应商明细datagrid
             * @param arr
             */
            function setSuppliersDatagrid(arr) {
                $('#suppliers').datagrid({
                    // fitColumns: true,
                    data: arr,
                    iconCls: 'icon-application',
                    clientPaging: true,
                    remoteFilter: false,
                    filterDelay: 0,
                    width: 850,
                    height: 300,
                    nowrap: true,
                    rownumbers: true,
                    animate: false,
                    collapsible: false,
                    singleSelect: true,
                    pagination: false,
                    frozenColumns: [[{
                        field: 'infId',
                        title: '供应商Id',
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : ''
                        }
                    },
                    {
                        field: 'gramId',
                        title: '方案Id',
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : ''
                        }
                    },
                    {
                        field: 'inqId',
                        title: '询价id',
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : ''
                        }
                    },
                    {
                        field: 'planId',
                        title: '采购计划id',
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : ''
                        }
                    },
                    {
                        field: 'resId',
                        title: '询价结果id',
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : ''
                        }
                    },
                    {
                        field: 'dealIsCheck',
                        title: '是否中选',
                        width: 100,
                        formatter: function (val, rec) {
                            return val == '1' ? '是' : '否'
                        },
                        editor: {
                            type: 'combobox',
                            options: {
                                data: dealIsCheckOptions,
                                valueField: "dealIsCheck",
                                textField: "text",
                                editable: false,
                                required: true,
                                /* onSelect: function (record) {
                                     var row = $("#suppliers").datagrid(
                                         'getSelected');
                                     // var rindex = $("#suppliers").datagrid('getRowIndex', row);
                                     var ed = $("#suppliers").datagrid(
                                         'getEditor', {
                                             index: editIndex,
                                             field: 'dealIsCheck'
                                         });
                                     let text = $(ed.target).combobox('getText');
                                     if (text == '是') {
                                         $(ed.target).combobox('setValue', '1')
                                     } else if(text == '否'){
                                         $(ed.target).combobox('setValue', '0')
                                     }
                                 }*/
                            }
                        }, styler: cellStyler
                    },
                    {
                        field: 'infName',
                        title: '供应商名称',
                        width: 200,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : ''
                        }
                    },
                    {
                        field: 'infCode',
                        title: '供应商编码',
                        op: ['less', 'greater'],
                        width: 100,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : ''
                        }
                    },]],
                    columns: [
                        [
                            /* {
                                 field: 'planName',
                                 title: '计划名称',
                                 sortable: true,
                                 width: 100,
                                 formatter: function (val, rec) {
                                     return val ? unescape(val) : ''
                                 }
                             },*/
                            {
                                field: 'infFirstTotalPrice',
                                title: '报价金额',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val.toLocaleString()) : 0
                                }
                            },
                            {
                                field: 'infFirstNum',
                                title: '报价数量',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : 0
                                }
                            },
                            {
                                field: 'infFirstUnitPrice',
                                title: '报价单价',
                                width: 100,
                                formatter: function (val, rec) {
                                    return rec.infFirstNum ? (Number(rec.infFirstTotalPrice) / Number(rec.infFirstNum)).toFixed(2) : 0
                                }
                            },
                            {
                                field: 'infLastTotalPrice',
                                title: '中标金额',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val.toLocaleString()) : 0
                                }
                            },
                            {
                                field: 'infNum',
                                title: '中标数量',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : 0
                                }
                            },
                            {
                                field: 'infUnitPrice',
                                title: '中标单价',
                                width: 100,
                                formatter: function (val, rec) {
                                    return rec.infNum ? ((rec.infLastTotalPrice ? Number(rec.infLastTotalPrice) : 0) / Number(rec.infNum)).toFixed(2) : 0
                                }
                            },
                            {
                                field: 'infTransportCost',
                                title: '运费金额',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : 0
                                }
                            },
                            {
                                field: 'infTransportPrice',
                                title: '运费净水价',
                                width: 100,
                                formatter: function (val, rec) {
                                    return rec.infNum ? (rec.infTransportCost / Number(rec.infNum).toFixed(2)) : 0
                                }
                            },
                            {
                                field: 'infContact',
                                title: '联系人',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'infContactTel',
                                title: '联系方式',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            // {
                            //     field: 'inqIsSettle',
                            //     title: '结算标识',
                            //     width: 100,
                            //     formatter: function (val, rec) {
                            //         return val == '1' ? '按原发数结算' : '按实收数结算'
                            //     },
                            //     editor: {
                            //         type: 'combobox',
                            //         options: {
                            //             data: inqIsSettleOptions,
                            //             valueField: "inqIsSettle",
                            //             textField: "text",
                            //             editable: false,
                            //             required: true,
                            //             onSelect: function (record) {
                            //                 var row = $("#suppliers").datagrid(
                            //                     'getSelected');
                            //                 // var rindex = $("#suppliers").datagrid('getRowIndex', row);
                            //                 var ed = $("#suppliers").datagrid(
                            //                     'getEditor', {
                            //                     index: editIndex,
                            //                     field: 'inqIsSettle'
                            //                 });
                            //                 let text = $(ed.target).combobox('getText');
                            //                 if (text == '按原发数结算') {
                            //                     $(ed.target).combobox('setValue', '1')
                            //                 } else {
                            //                     $(ed.target).combobox('setValue', '2')
                            //                 }
                            //             }
                            //         }
                            //     }, styler: cellStyler
                            // },
                            // {
                            //     field: 'inqIsWeight',
                            //     title: '是否过磅',
                            //     width: 100,
                            //     formatter: function (val, rec) {
                            //         return val == '1' ? '无需过磅' : '需过磅'
                            //     },
                            //     editor: {
                            //         type: 'combobox',
                            //         options: {
                            //             data: inqIsWeightOptions,
                            //             valueField: "inqIsWeight",
                            //             textField: "text",
                            //             editable: false,
                            //             required: true,
                            //             onSelect: function (record) {
                            //                 var row = $("#suppliers").datagrid(
                            //                     'getSelected');
                            //                 // var rindex = $("#suppliers").datagrid('getRowIndex', row);
                            //                 var ed = $("#suppliers").datagrid(
                            //                     'getEditor', {
                            //                     index: editIndex,
                            //                     field: 'inqIsWeight'
                            //                 });
                            //                 let text = $(ed.target).combobox('getText');
                            //                 if (text == '无需过磅') {
                            //                     $(ed.target).combobox('setValue', '1')
                            //                 } else {
                            //                     $(ed.target).combobox('setValue', '2')
                            //                 }
                            //             }
                            //         }, styler: cellStyler
                            //     }
                            // },
                            // {
                            //     field: 'inqIsOwn',
                            //     title: '是否自提',
                            //     width: 100,
                            //     formatter: function (val, rec) {
                            //         return val == '1' ? '自提' : '供应商送货'
                            //     },
                            //     editor: {
                            //         type: 'combobox',
                            //         options: {
                            //             data: inqIsOwnOptions,
                            //             valueField: "inqIsOwn",
                            //             textField: "text",
                            //             editable: false,
                            //             required: true,
                            //             onSelect: function (record) {
                            //                 var row = $("#suppliers").datagrid(
                            //                     'getSelected');
                            //                 // var rindex = $("#suppliers").datagrid('getRowIndex', row);
                            //                 var ed = $("#suppliers").datagrid(
                            //                     'getEditor', {
                            //                     index: editIndex,
                            //                     field: 'inqIsOwn'
                            //                 });
                            //                 let text = $(ed.target).combobox('getText');
                            //                 if (text == '自提') {
                            //                     $(ed.target).combobox('setValue', '1')
                            //                 } else {
                            //                     $(ed.target).combobox('setValue', '2')
                            //                 }
                            //             }
                            //         }, styler: cellStyler
                            //     }
                            // },
                            //                     {
                            //                         field: 'inqPayment',
                            //                         title: '付款条款描述',
                            //                         sortable: true,
                            //                         width: 200,
                            //                         formatter: function (val, rec) {
                            //                             return val ? unescape(val) : ''
                            //                         }
                            //                     },
                            // {
                            //     field: 'inqPaymentCode',
                            //     title: '付款条款',
                            //     width: 230,
                            //     editor: {
                            //         type: 'combobox',
                            //         options: {
                            //             url: 'sysDict/queryItemByTypeName?dicName=付款条件',
                            //             method: 'get',
                            //             valueField: "dicValue",
                            //             textField: "dicName",
                            //             editable: false,
                            //             required: true,
                            //             onSelect: function (record) {
                            //                 //                                     let suppliyRow = $('#suppliers').datagrid('getSelected');
                            //                 //                                     suppliyRow.inqPayment = record.dicName;
                            //                 //                                     suppliyRow.inqPaymentCode = record.dicValue;
                            //                 //                                     console.log(suppliyRow);
                            //             }
                            //         }
                            //     },
                            //     formatter: function (val, rec) {
                            //         return rec.inqPayment;
                            //     }, styler: cellStyler
                            // },
                            //                         {
                            //                             field: 'inqCurrency',
                            //                             title: '币种',
                            //                             sortable: true,
                            //                             width: 100,
                            //                             formatter: function (val, rec) {
                            //                                 return val ? unescape(val) : ''
                            //                             }
                            //                         },
                            // {
                            //     field: 'inqCurrencyCode',
                            //     title: '币种代码',
                            //     editor: {
                            //         type: 'combobox',
                            //         options: {
                            //             url: 'sysDict/queryItemByTypeName?dicName=币种',
                            //             method: 'get',
                            //             valueField: "dicValue",
                            //             textField: "dicName",
                            //             editable: false,
                            //             required: true,
                            //             onSelect: function (record) {
                            //                 let suppliyRow = $('#suppliers').datagrid('getSelected')
                            //                 suppliyRow.inqCurrency = record.dicName
                            //             }
                            //         }
                            //     },
                            //     width: 100,
                            //     formatter: function (val, rec) {
                            //         return val ? unescape(rec.inqCurrency) : ''
                            //     }, styler: cellStyler
                            // },
                            {
                                field: 'remark',
                                title: '备注',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'inqOfrTime',
                                title: '提交时间',
                                op: ['less', 'greater'],
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'inqStartTime',
                                title: '报价开始时间',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'inqEndTime',
                                title: '报价结束时间',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'createName',
                                title: '创建人',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'createTime',
                                title: '创建时间',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'updateTime',
                                title: '更新时间',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'status ',
                                title: '状态',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            }
                        ]
                    ],
                    toolbar: [{
                        text: '维护报价',
                        iconCls: 'icon-search',
                        handler: function () {
                            checkOfferOfSuppliers();

                        }
                    }, '-',],
                    onEndEdit: onEndEdit,
                    onClickCell: onClickCell
                })
            }

            function onEndEdit(index, row) {
                // var ed = $(this).datagrid('getEditor', {
                //     index: index,
                //     field: 'inqPaymentCode'
                // });
                // row.inqPayment = $(ed.target).combobox('getText');

                // ed = $(this).datagrid('getEditor', {
                //     index: index,
                //     field: 'inqCurrencyCode'
                // });
                // row.inqCurrency = $(ed.target).combobox('getText');
            }

            function onClickCell(index, field) {
                console.log('onClickCell====', editIndex, '---index===', index)
                if (editIndex != index) {
                    if (endEditing()) {
                        $('#suppliers').datagrid('selectRow', index)
                            .datagrid('beginEdit', index);
                        var ed = $('#suppliers').datagrid('getEditor', { index: index, field: field });
                        if (ed) {
                            //  ($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
                        }
                        editIndex = index;
                    } else {
                        setTimeout(function () {
                            $('#suppliers').datagrid('selectRow', editIndex);
                        }, 0);
                    }
                }
            }

            /**
             * 构建物资报价明细的datagrid
             */
            function setMmsOfferDatagrid(arr) {
                let createId = '', status = 0;
                for (let item of arr) {
                    createId = item.createId;
                    status = item.status;
                    item.inqTransportTaxPrice = item.inqTransportTaxPrice >= 0 ? item.inqTransportTaxPrice : 0.0000;
                    item.dealNum = item.dealNum >= 0 ? item.dealNum : item.inqOfrNum;
                    item.dealLastUnit = item.dealLastUnit >= 0 ? item.dealLastUnit : item.inqOfrUnitPrice;
                    item.dealUnitPrice = item.dealUnitPrice >= 0 ? item.dealUnitPrice : item.dealLastUnit;
                    item.dealTotalPrice = item.dealTotalPrice >= 0 ? item.dealTotalPrice : item.inqOfrTotalPrice;
                }
                console.log('arr:', arr);
                // 构建供应商物资报价明细
                let mmOffers = $('#mmOffers')
                mmOffers.datagrid({
                    // fitColumns: true,
                    data: arr,
                    iconCls: 'icon-application',
                    // clientPaging: true,
                    remoteFilter: false,
                    filterDelay: 0,
                    width: 860,
                    height: 300,
                    nowrap: true,
                    rownumbers: true,
                    animate: false,
                    collapsible: false,
                    singleSelect: true,
                    pageSize: 10,
                    remoteSort: false,
                    // pagination: true,
                    frozenColumns: [[{
                        field: 'infId',
                        title: '供应商Id',
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : ''
                        }
                    },
                    {
                        field: 'resId',
                        title: '询价结果id',
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : ''
                        }
                    },
                    {
                        field: 'inqId',
                        title: '询价id',
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : ''
                        }
                    },

                    {
                        field: 'planId',
                        title: '归口编码',
                        formatter: function (val, rec) {
                            return val ? unescape(val) : ''
                        }
                    },
                    {
                        field: 'gramId',
                        title: '方案Id',
                        hidden: true,
                        formatter: function (val, rec) {
                            return val ? unescape(val) : ''
                        }
                    },
                    {
                        field: 'mmCode',
                        title: '物资编码',
                        formatter: function (val, rec) {
                            return val ? val : ''
                        },
                    },
                    {
                        field: 'mmDetail',
                        title: '物资描述',
                        width: 210,
                        formatter: function (val, rec) {
                            if (val) {
                                return '<span title="' + val + '">' + val + '</span>';
                            } else {
                                return val;
                            }
                        }
                    },]],
                    columns: [
                        [
                            {
                                field: 'mmMain',
                                title: '主特征',
                                sortable: true,
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'mmUnit',
                                title: '计量单位',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'mmUnitDetail',
                                title: '计量单位描述',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'planFactoryCode',
                                title: '到货工厂',
                                formatter: function (val, rec) {
                                    return val ? val : ''
                                },
                            },
                            {
                                field: 'inqOfrNum',
                                title: '报价数量',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? val : ''
                                },
                                /*editor: {
                                    type: 'numberbox'
                                }*/
                            },
                            {
                                field: 'inqOfrUnitPrice',
                                title: '报价单价',
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? val : ''
                                },
                                /*editor: {
                                    type: 'numberbox'
                                }*/
                            },
                            {
                                field: 'inqOfrTotalPrice',
                                title: '报价金额',
                                formatter: function (val, rec) {
                                    return val ? val.toLocaleString() : ''
                                },
                                /*editor: {
                                    type: 'numberbox'
                                }*/
                            },
                            {
                                field: 'inqTransportTaxPrice',
                                title: '运费单价',
                                width: 100,
                                editor: {
                                    type: 'numberbox',
                                    options: {
                                        disabled: status == 0 ? false : true,
                                        required: true, precision: 2
                                    }
                                },
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : '0'
                                }, styler: cellStyler
                            },
                            {
                                field: 'inqTransportTaxRate',
                                title: '运费税码',
                                width: 70,
                                editor: {
                                    type: 'combobox',
                                    options: {
                                        disabled: status == 0 ? false : true,
                                        url: 'sysDict/queryItemByTypeName?dicName=运费税率',
                                        method: 'get',
                                        valueField: "dicValue",
                                        textField: "dicName",
                                        editable: false,
                                        required: true
                                    }
                                },
                                formatter: function (val, rec) {
                                    return rec.inqTransportTaxRate;
                                }, styler: cellStyler
                            },
                            {
                                field: 'inqTransportTotalPrice',
                                title: '运费金额',
                                width: 100,
                                /* editor: {
                                     type: 'numberbox'
                                 },*/
                                formatter: function (val, rec) {
                                    return val
                                }, styler: cellStyler
                            },
                            {
                                field: 'inqTransportUnitPrice',
                                title: '运费净水价',
                                width: 100,
                                sortable: true,
                                formatter: function (val, rec) {
                                    return val
                                }
                            },
                            // {
                            //     field: 'inqStockAddressCode',
                            //     title: '库存地点',
                            //     width: 200,
                            // editor: {
                            //     type: 'combobox',
                            //                                 options: {
                            //                                     url: addressUrl,
                            //                                     method: 'get',
                            //                                     valueField: "dicValue",
                            //                                     textField: "dicName",
                            //                                     editable: false,
                            //                                     required: true,
                            //                                     width:100
                            //                                 }
                            // },
                            //     formatter: function (val, rec) {
                            //         return rec.inqStockAddress;
                            //     }, styler: cellStyler
                            // },
                            // {
                            //     field: 'inqBackGood',
                            //     title: '退货标记',
                            //     formatter: function (val, rec) {
                            //         return val == 'X' ? '退货' : '采购'
                            //     },
                            //     editor: {
                            //         type: 'combobox',
                            //         options: {
                            //             data: inqBackGoodOptions,
                            //             valueField: "inqBackGood",
                            //             textField: "text",
                            //             editable: false,
                            //             required: true
                            //         }
                            //     }, styler: cellStyler
                            // },
                            // {
                            //     field: 'inqIsFree',
                            //     title: '免费标记',
                            //     formatter: function (val, rec) {
                            //         return val == 'X' ? '免费' : '付费'
                            //     },
                            //     editor: {
                            //         type: 'combobox',
                            //         options: {
                            //             data: inqIsFreeOptions,
                            //             valueField: "inqIsFree",
                            //             textField: "text",
                            //             editable: false,
                            //             required: true
                            //         }
                            //     }, styler: cellStyler
                            // },
                            {
                                field: 'inqDeliverDate',
                                title: '交货日期',
                                width: 100,
                                editor: {
                                    options: {
                                        disabled: status == 0 ? false : true
                                    },
                                    type: 'datebox', editable: false
                                },
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            /*{
                                field: 'inqOfrExcludePrice',
                                title: '不含税价格',
                                sortable: true,
                                editor: {
                                    type: 'numberbox'
                                },
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },*/
                            {
                                field: 'dealNum',
                                title: '中标数量',
                                width: 100,
                                editor: {
                                    type: 'numberbox',
                                    options: {
                                        disabled: status == 0 ? false : true,
                                        required: true, precision: 4
                                    }
                                },
                                formatter: function (val, rec) {
                                    return val
                                }, styler: cellStyler
                            },
                            {
                                field: 'dealLastUnit',
                                title: '中标单价',
                                width: 100,
                                editor: {
                                    type: 'numberbox',
                                    options: {
                                        disabled: status == 0 ? false : true,
                                        required: true, precision: 2
                                    }
                                },
                                formatter: function (val, rec) {
                                    return val
                                }, styler: cellStyler
                            },
                            {
                                field: 'dealUnitPrice',
                                title: '最终单价',
                                width: 100,
                                editor: {
                                    type: 'numberbox',
                                    options: {
                                        disabled: PUser.btnPermission ? (PUser.btnPermission.indexOf(',purchase') >= 0 ? false : true) : true,
                                        precision: 2
                                    }
                                },
                                formatter: function (val, rec) {
                                    return val
                                }, styler: cellStyler
                            },
                            {
                                field: 'dealTotalPrice',
                                title: '中标金额',
                                width: 100,
                                /*editor: {
                                    type: 'numberbox'
                                },*/
                                formatter: function (val, rec) {
                                    return val ? unescape(val.toLocaleString()) : 0
                                }
                            },
                            {
                                field: 'inqTaxNum',
                                title: '税码',
                                width: 120,
                                editor: {
                                    type: 'combobox',
                                    options: {
                                        disabled: status == 0 ? false : true,
                                        url: 'sysDict/queryItemByTypeName?dicName=税码',
                                        method: 'get',
                                        valueField: "dicValue",
                                        textField: "dicName",
                                        editable: false,
                                        required: false
                                    }
                                },
                                formatter: function (val, rec) {
                                    return rec.inqTaxRate;
                                }, styler: cellStyler
                            },
                            {
                                field: 'gramUseName',
                                title: '联系人',
                                sortable: true,
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'gramUseTel',
                                title: '联系方式',
                                sortable: true,
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'lastUnit',
                                title: '最近成交价',
                                sortable: true,
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'lowUnit',
                                title: '最低成交价',
                                sortable: true,
                                width: 100,
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'remark',
                                title: '备注',
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'createName',
                                title: '创建人',
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'createTime',
                                title: '创建时间',
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            {
                                field: 'updateTime',
                                title: '更新时间',
                                formatter: function (val, rec) {
                                    return val ? unescape(val) : ''
                                }
                            },
                            /* {
                                 field: 'status ',
                                 title: '状态',
                                 sortable: true,
                                 width: 500,
                                 formatter: function (val, rec) {
                                     return val ? unescape(val) : ''
                                 }
                             }*/
                        ]
                    ],
                    toolbar: [{
                        text: '确定',
                        iconCls: 'icon-ok',
                        handler: function () {
                            if (endEditingMMs()) {
                                $('#mmOffers').datagrid('acceptChanges');
                                $('#mmOffersWindow').window('close')
                            }

                        }
                    }, {
                        text: '一键填充',
                        iconCls: 'icon-down',
                        handler: function () {
                            $.messager.confirm("提示", "确认向下复制第一行税码、交货日期等信息?", function (e) {
                                if (e) {
                                    if (endEditingMMs()) {
                                        var rows = $('#mmOffers').datagrid('getRows');
                                        for (let i = 1; i < rows.length; i++) {
                                            var row = rows[i];
                                            // row.inqIsFree = rows[0].inqIsFree;
                                            // row.inqBackGood = rows[0].inqBackGood;
                                            row.inqTransportTaxRate = rows[0].inqTransportTaxRate;
                                            row.inqTaxRate = rows[0].inqTaxRate;
                                            row.inqTaxNum = rows[0].inqTaxNum;
                                            // row.inqStockAddressCode = rows[0].inqStockAddressCode;
                                            // row.inqStockAddress = rows[0].inqStockAddress;
                                            row.inqDeliverDate = rows[0].inqDeliverDate;
                                            $('#mmOffers').datagrid('updateRow', { index: i, row: row });
                                            $('#mmOffers').datagrid('refreshRow', i);
                                        }
                                        //                                         $('#mmOffers').datagrid('acceptChanges');
                                        // $('#mmOffers').datagrid('reload');
                                    }
                                }
                            })
                        }
                    }],
                    onEndEdit: onEndEditMm,
                    onClickCell: onClickCellMm
                })
            }

            function onClickCellMm(index, field) {
                if (editIndexMm != index) {
                    if (endEditingMMs()) {
                        $('#mmOffers').datagrid('selectRow', index)
                            .datagrid('beginEdit', index);
                        var ed = $('#mmOffers').datagrid('getEditor', { index: index, field: field });
                        var row = $('#mmOffers').datagrid('getRows')[index];

                        var addressUrl = 'sysDict/queryItemByTypeName?dicName=' + row.planFactoryCode + '-库存地点';
                        //此处field为第二个下拉列的field
                        // let appTarget = $('#mmOffers').datagrid('getEditor', {
                        //     index: index,
                        //     field: 'inqStockAddressCode'
                        // }).target;

                        // if (appTarget.combobox('getData').length == 0) {
                        //     //清空
                        //     appTarget.combobox('clear');
                        //     appTarget.combobox({
                        //         url: addressUrl,
                        //         method: 'get',
                        //         valueField: "dicValue",
                        //         textField: "dicName",
                        //         editable: false,
                        //         required: true
                        //     });
                        //     appTarget.combobox('setValue', row.inqStockAddressCode);
                        // }
                        if (ed) {
                            //  ($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
                        }
                        editIndexMm = index;
                    } else {
                        setTimeout(function () {
                            $('#mmOffers').datagrid('selectRow', editIndexMm);
                        }, 0);
                    }
                }
            }

            function onEndEditMm(index, row) {
                // var ed = $(this).datagrid('getEditor', {
                //     index: index,
                //     field: 'inqStockAddressCode'
                // });
                // row.inqStockAddress = $(ed.target).combobox('getText');

                var ed = $(this).datagrid('getEditor', {
                    index: index,
                    field: 'inqTaxNum'
                });
                row.inqTaxRate = $(ed.target).combobox('getText');

                ed = $(this).datagrid('getEditor', {
                    index: index,
                    field: 'inqTransportTaxRate'
                });
                row.inqTransportTaxRate = $(ed.target).combobox('getText');
            }

            /**
             * 条件查询询价结果列表
             */
            function searchInquiryResultList() {
                let startTime = $('#startTime').datebox('getValue')
                let endTime = $('#endTime').datebox('getValue')
                let status = $('#status').combobox('getValue')
                let dg = $('#initTable')
                dg.datagrid('enableFilter')
                dg.datagrid('load', {
                    startTime: startTime ? startTime : '',
                    endTime: endTime ? endTime : '',
                    status: status ? status : ''
                })
            }

            /**
             *删除询价结果
             **/
            function deleteInquiryResult(resId) {
                $.ajax({
                    type: "delete",
                    url: "purchase/result/delResult?resId=" + resId,
                    // data: JSON.stringify(queryData),
                    success: function (data) {
                        if (data.code != 60200) {
                            $.messager.alert('消息', data.msg);
                        } else {
                            let dg = $('#initTable');
                            dg.datagrid('enableFilter');
                            dg.datagrid('load');
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                });
            }

            // 导出为Excel
            function exportInquiryList() {
                let startTime = $('#startTime').datebox('getValue')
                let endTime = $('#endTime').datebox('getValue')
                let status = $('#status').combobox('getValue')
                var form = [];
                form.push('startTime=' + (startTime ? startTime : ''));
                form.push('endTime=' + (endTime ? endTime : ''));
                form.push('status=' + (status ? status : ''));
                let url = 'api/purchase/result/export'
                let xhr = new XMLHttpRequest()
                xhr.open('POST', url, true)
                xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                xhr.setRequestHeader('token', localStorage.getItem('token'));
                xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                xhr.responseType = 'blob'
                xhr.onload = function () {
                    if (this.status == 200) {
                        let blob = this.response
                        let reader = new FileReader()
                        reader.readAsDataURL(blob)
                        reader.onload = function (e) {
                            let a = document.createElement('a')
                            a.download = '询价结果' + new Date().getTime() + '.xlsx'
                            a.href = e.target.result
                            $('body').append(a)
                            a.click()
                            $(a).remove()
                        }
                    }
                }
                xhr.send(form.join('&'))
            }

            /**
             * 初始化询价结果列表
             */
            function bingGrid() {
                let startTime = $('#startTime').datebox('getValue')
                let endTime = $('#endTime').datebox('getValue')
                let status = $('#status').combobox('getValue')
                let dg = $('#initTable');
                dg.datagrid({
                    title: '',
                    queryParams: {
                        startTime: startTime ? startTime : '',
                        endTime: endTime ? endTime : '',
                        status: status
                    },
                    url: 'purchase/result/selectResultList',
                    iconCls: 'icon-application',
                    clientPaging: false,
                    remoteFilter: true,
                    filterDelay: 0,
                    width: getWidth(0.98),
                    height: 400,
                    nowrap: true,
                    rownumbers: true,
                    animate: false,
                    collapsible: false,
                    singleSelect: true,
                    pageSize: 10,
                    remoteSort: true,
                    pagination: true,
                    frozenColumns: [[{
                        field: 'resId',
                        title: '询价结果id',
                        hidden: true,
                        sortable: true,
                        width: 100,
                        formatter: function (val, rec) {
                            return unescape(val)
                        }
                    },
                    {
                        field: 'inqId',
                        title: '询价ID',
                        hidden: true,
                        sortable: true,
                        width: 100,
                        formatter: function (val, rec) {
                            return unescape(val)
                        }
                    },
                    {
                        field: 'gramId',
                        title: '方案id',
                        hidden: true,
                        sortable: true,
                        width: 100,
                        formatter: function (val, rec) {
                            return unescape(val)
                        }
                    },
                    {
                        field: 'resCode',
                        title: '结果编码',
                        sortable: true,
                        formatter: function (val, rec, index) {
                            return '<a href="javascript:void(0)" onclick="inquiryResultDetail(' + index +
                                ')">' + (val ? val : '') + '</a>'

                        }
                    },
                    {
                        field: 'inqName',
                        title: '询价名称',
                        sortable: true,
                        formatter: function (val, rec, index) {

                            return val ? val : ''

                        }
                    },
                    {
                        field: 'inqCode',
                        title: '询价编码',
                        sortable: true,
                        formatter: function (val, rec) {
                            return unescape(val ? val : '')
                        }
                    },]],
                    columns: [
                        [

                            /*{
                                field: 'gramName',
                                title: '采购方案名称',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },*/
                            {
                                field: 'resNum',
                                title: '中标数量',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'resMoney',
                                title: '中标金额',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val.toLocaleString() : '')
                                }
                            },
                            {
                                field: 'resUnit',
                                title: '中标单位',
                                width: 300,
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'inqOfferMode',
                                title: '报价方式',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            /* {
                               field: 'inqDealMode',
                               title: '成交方式',
                               sortable: true,
                               formatter: function (val, rec) {
                                 return unescape(val ? val : '')
                               }
                             },
                             {
                               field: 'inqStartTime',
                               title: '报价开始时间',
                               sortable: true,
                               formatter: function (val, rec) {
                                 return unescape(val ? val : '')
                               }
                             },
                             {
                               field: 'inqEndTime',
                               title: '报价结束时间',
                               sortable: true,
                               formatter: function (val, rec) {
                                 return unescape(val ? val : '')
                               }
                             },
                             
                             {
                                 field: 'inqRevealTime',
                                 title: '报价揭示时间',
                                 sortable: true,
                                 formatter: function (val, rec) {
                                     return unescape(val ? val : '')
                                 }
                             },*/
                            {
                                field: 'inqActualTime',
                                title: '实际揭示时间',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            // {
                            //     field: 'inqClause',
                            //     title: '价格条款',
                            //     sortable: true,
                            //     formatter: function (val, rec) {
                            //         return unescape(val ? val : '')
                            //     }
                            // },
                            {
                                field: 'inqActualName',
                                title: '合同执行人',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'oaFlowId',
                                title: 'oa流程id',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'createName',
                                title: '创建人',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'createTime',
                                title: '创建时间',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'updateTime',
                                title: '更新时间',
                                sortable: true,
                                formatter: function (val, rec) {
                                    return unescape(val ? val : '')
                                }
                            },
                            {
                                field: 'status',
                                title: '状态',
                                op: ['less', 'greater'],
                                //sortable : true,
                                formatter: function (val, rec) {
                                    let status = val ? val : '';
                                    return unescape(status == '0' ? '待提交' : (status == '2' ? '已完成' : '已提交'));
                                }
                            },
                        ]
                    ],
                    toolbar: [{
                        text: '新增',
                        iconCls: 'icon-add',
                        handler: function () {
                            addInquirResult();
                        }
                    },
                        '-',
                    {
                        text: '编辑',
                        iconCls: 'icon-edit',
                        handler: function () {
                            updateInquiryResult();
                        }
                    },
                        '-',
                    {
                        text: '删除',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            //删除
                            let row = $('#initTable').datagrid('getSelected');
                            if (row) {
                                if (+row.status == '2') {
                                    $.messager.confirm('提示', '该数据已提交，无法删除')
                                    return
                                }
                                if (+row.status == '1') {
                                    $.messager.confirm('提示', '该数据已提交，无法删除')
                                    return
                                } else {
                                    $.messager.confirm('提示', '确定要删除吗?',
                                        function (r) {
                                            if (r) {
                                                deleteInquiryResult(row.resId);
                                            }
                                        });
                                }

                            } else {
                                $.messager.alert('消息', '请选中一个要删除的数据');
                            }
                        }
                    }
                        ,
                        '-',
                    {
                        text: '撤回',
                        iconCls: 'icon-undo',
                        handler: function () {
                            //撤回
                            let row = $('#initTable').datagrid('getSelected');
                            if (row) {
                                if (row.status == '2') {
                                    $.messager.alert('提示', '该单据已完成，无法撤回')
                                    return
                                }
                                if (+row.status != '1') {
                                    $.messager.confirm('提示', '该数据未提交，无需撤回')
                                    return
                                } else {
                                    $.messager.confirm('提示', '请先确认已退回流程在oa待办事宜里，确定要撤回吗?',
                                        function (r) {
                                            if (r) {
                                                backupResult(row);
                                            }
                                        });
                                }

                            } else {
                                $.messager.alert('消息', '请选择要撤回的数据');
                            }
                        }
                    },
                        '-',
                    {
                        text: '采购部审核',
                        iconCls: 'icon-edit',
                        disabled: PUser.btnPermission ? (PUser.btnPermission.indexOf(',purchase') >= 0 ? false : true) : true,
                        handler: function () {
                            checkInquiryResult();
                        }
                    },
                    ],
                    onLoadSuccess: function () {

                    },
                    onDblClickRow: function () {
                        var obj = document.getElementById('uploadpicker');
                        obj.outerHTML = obj.outerHTML;
                        updateInquiryResult();
                    }
                });

                dg.datagrid('enableFilter');
            }

            /***
             * 撤回询价结果
             */
            function backupResult(resultObj) {
                $.ajax({
                    type: 'post',
                    url: 'purchase/result/back',
                    data: JSON.stringify(resultObj),
                    dataType: 'json',
                    contentType: "application/json",
                    success: function (data) {
                        if (data.code == 60200) {
                            $.messager.alert('消息', data.msg)
                            let dg = $('#initTable');
                            dg.datagrid('enableFilter');
                            dg.datagrid('load');
                        } else {
                            $.messager.alert('消息', data.msg)
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                })
            }


            /***
             * 条件查询
             */
            function selectInquiryList() {
                let startTime = $('#startInquiryTime').datebox('getValue')
                let endTime = $('#endInquiryTime').datebox('getValue')
                // let status = $('#statusInq').datebox('getValue')
                let dg = $('#inquiryList');
                dg.datagrid('enableFilter');
                dg.datagrid('load', {
                    startTime: startTime ? startTime : '',
                    endTime: endTime ? endTime : '',
                    inqRevealStatus: '1'
                })
            }


            /************文件处理部分*************/

            /**
             * 保存附件
             */

            function saveAttch(row, obj, action) {
                obj.resId = row
                let saveNum = 0
                if (selectedFileList.length > 0) {
                    $.each(selectedFileList, function (index, item) {
                        showFilediv();
                        var dataform = new FormData();
                        dataform.append("file", item);
                        var xmlhttp = null;
                        if (window.XMLHttpRequest) { // code for all new browsers
                            xmlhttp = new XMLHttpRequest();
                        } else if (window.ActiveXObject) {// code for IE5 and IE6
                            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        if (xmlhttp != null) {
                            xmlhttp.open("POST", "api/file/springUpload?fileRow=" + row
                                + "&fileTable=purchase_inquiry_result&fileName="
                                + item.name, true);
                            xmlhttp.setRequestHeader('token', localStorage.getItem('token'));
                            xmlhttp.setRequestHeader('userType', localStorage.getItem('userType'));
                            xmlhttp.send(dataform);
                            xmlhttp.onreadystatechange = callbackMethods;
                        } else {
                            alert("你的浏览器版本不兼容，请使用更高版本的浏览器");
                        }

                        function callbackMethods() {
                            if (xmlhttp.readyState == 4) {
                                if (xmlhttp.status == 200) {
                                    saveNum += 1
                                    if (saveNum == selectedFileList.length) {
                                        hideFilediv();
                                        if ('submit' == action) {
                                            commitResult(obj)
                                        } else {
                                            $.messager.show({
                                                title: '提示',
                                                msg: '保存成功',
                                                timeout: 3000,
                                                showType: 'slide'
                                            });
                                            let dg = $('#initTable');
                                            // 刷新列表
                                            dg.datagrid('enableFilter');
                                            dg.datagrid('load');
                                            $('#resultDetaillWindow').window('close');
                                            getResult(obj.resId)

                                        }
                                    }
                                }
                            } else {
                                if (xmlhttp.status == 500) {
                                }
                            }
                        }
                    });
                } else {
                    if ('submit' == action) {
                        commitResult(obj)
                    } else {
                        $.messager.show({
                            title: '提示',
                            msg: '保存成功',
                            timeout: 3000,
                            showType: 'slide'
                        });
                        let dg = $('#initTable');
                        // 刷新列表
                        dg.datagrid('enableFilter');
                        dg.datagrid('load');
                        $('#resultDetaillWindow').window('close');
                        getResult(obj.resId)

                    }
                }
            }

            /**
             *文件框改变事件
             */
            function changeFile() {
                var files = $("#uploadpicker").prop("files");
                $.each(
                    files,
                    function (index, item) {
                        let choiseFile = $("#checkfileList>li");
                        if (choiseFile.length > 0) {//文件去重
                            let count = 0;
                            $.each(choiseFile, function (index1, item1) {
                                if (item.name == item1.innerText) {
                                    count++;
                                }
                            });
                            if (count == 0) {
                                if (checkFileLength(item.size)) {
                                    if (item.name.includes('#') || item.name.includes('/') || item.name.includes('&') || item.name.includes('\\') || item.name.includes(' ')) {
                                        alert('文件名不能包含&、斜杠、反斜杠、空格等特殊字符！');
                                        return;
                                    }
                                    $("#checkfileList")
                                        .append(
                                            "<li class=\"fileinfo\">"
                                            + item.name
                                            + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                            + item.name
                                            + "')\">删除</a>"
                                            + "</li>");
                                    selectedFileList.push(item);
                                    AddMoushover();
                                }
                            }
                        } else {
                            if (checkFileLength(item.size)) {
                                if (item.name.includes('#') || item.name.includes('/') || item.name.includes('&') || item.name.includes('\\') || item.name.includes(' ')) {
                                    alert('文件名不能包含&、斜杠、反斜杠、空格等特殊字符！');
                                    return;
                                }
                                $("#checkfileList")
                                    .append(
                                        "<li class=\"fileinfo\">"
                                        + item.name
                                        + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                        + item.name
                                        + "')\">删除</a>"
                                        + "</li>");
                                selectedFileList.push(item);
                                AddMoushover();
                            }
                        }
                    });
            }

            /**
             *    判断文件是否超过限制大小
             * @param fileLen
             * @returns {boolean}
             */
            function checkFileLength(fileLen) {
                if (fileLen > 102400000) {
                    $.messager.alert("提示", "上传文件大小不能超过100M", "error");
                    return false;
                }
                return true;
            }

            /**
             * //添加鼠标经过事件，鼠标划过时显示“删除”
             * @constructor
             */
            function AddMoushover() {
                $(".fileinfo").hover(function () {
                    $(this).find("a").last().css("display", "");
                }, function () {
                    $(this).find("a").last().css("display", "none");
                });
            }

            /**
             *  移除已选择的文件
             */

            function RemoveFile(obj, fileId) {
                $.messager.confirm("提示", "确认删除当前文件?", function (e) {
                    if (e) {
                        let index = $("#checkfileList>li").index($(obj).parent());
                        selectedFileList.splice(index, 1);
                        $(obj).parent().remove();

                        $.ajax({
                            type: "post",
                            url: 'file/deleteFile?fileId=' + fileId,
                            success: function (data) {
                                $.messager.alert('消息', data);
                            },
                            error: function (XMLHttpRequest, textStatus,
                                errorThrown) {
                                $.messager.alert('消息', errorThrown);
                            }
                        });

                    }
                });
            }

            /**
             * 取得该条数据所属的文件列表
             * @param row
             */
            function getFileList(row, status) {
                $.ajax({
                    type: "post",
                    url: "file/getFileList",
                    data: {
                        fileTable: "purchase_inquiry_result",
                        fileRow: row.resId
                    },
                    success: function (data) {
                        const dataArray = eval(data);
                        initFile(dataArray, row.status);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.messager.alert('消息', errorThrown);
                    }
                });
            }

            /**
             * 初始化该条数据的文件列表
             * @param dataArray
             */
            function initFile(dataArray, status) {
                $("#checkfileList").empty();
                // 			sselectedFileNameList = [];
                selectedFileList = [];
                dataArray
                    .forEach(function (e, i, a) {
                        $("#checkfileList")
                            .append(
                                "<li class=\"fileinfo\">"
                                + "<a style=\" color: blue; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"downloadFile('" + e.FILE_NAME + "','"
                                + e.FILE_ID
                                + "')\">"
                                + e.FILE_NAME
                                + (status > 0 ? '' : "<a style=\"display: none; color: red; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                    + e.FILE_ID + "')\">删除</a>")
                                + "</li>");
                        // 						sselectedFileNameList.push(e.FILE_NAME);

                        if (status > 0) {
                        } else {
                            AddMoushover();
                        }
                    });
            }

            // 文件下载
            function downloadFile(fileName, fileRow) {
                let url = 'api/file/download?id=' + fileRow
                let xhr = new XMLHttpRequest()
                xhr.open('GET', url, true)
                xhr.setRequestHeader('token', localStorage.getItem('token'));
                xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                xhr.responseType = 'blob'
                xhr.onload = function (data) {
                    if (this.status == 200) {
                        let blob = this.response
                        let reader = new FileReader()
                        reader.readAsDataURL(blob)
                        reader.onload = function (e) {
                            let a = document.createElement('a')
                            a.download = fileName
                            a.href = e.target.result
                            $('body').append(a)
                            a.click()
                            $(a).remove()
                        }
                    } else {

                    }
                }
                xhr.send()
            }
        </script>

        </html>